﻿@model PrjAssessModels.BaseModels.Project
@{
    ViewBag.Title = "管理考核";
}

<div data-ng-app="myapp" data-ng-controller="myCtrl">
    <div class="container">
        <h6 ><a href="#"   class="btn btn-default btn-sm pull-right" data-ng-click="collapse()">折叠/显示所有考核选项</a>&nbsp;</h6>
        <br />
        <div class="panel panel-default">
            <div class="panel-heading" >
                 <h5><a href="#" data-ng-init="planShow = false"  data-ng-click="planShow = !planShow">方案编制</a></h5>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-xs-6">
                        <form action="/" method="post" data-ng-show="planShow==true">
                            <div class="form-group">
                                <label for="质量系数">质量系数</label>
                                <select class="form-control" required name="质量系数" data-ng-model="model_QualityRatio"
                                    data-ng-options="s for s in QualityRatio">
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="是否中标">是否中标</label>
                                <select class="form-control" required name="是否中标" data-ng-model="model_IsBid"
                                    data-ng-options="s.value as s.label for s in IsBid">
                                </select>
                            </div>

                        </form>
                    </div>
                    <div class="col-xs-6">
                        <form action="/" method="post" data-ng-show="planShow==true">
                            <div class="form-group">
                                <label for="是否外聘编写">是否外聘编写</label>
                                <select class="form-control" required name="是否中标" data-ng-model="model_IsWritten"
                                    data-ng-options="s.value as s.label for s in IsWritten">
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="是否陪标">是否陪标</label>
                                <select class="form-control" required name="是否陪标" data-ng-model="model_IsAccompany"
                                    data-ng-options="s.value as s.label for s in IsAccompany">
                                </select>
                            </div>

                        </form>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary pull-right" data-ng-click="savePlan()" data-ng-show="planShow==true">考核方案编制</button>
                <h5><span class="text-muted">额度:&nbsp;</span><strong>{{planTotal}}￥</strong>&nbsp;&nbsp;
                            <span class="text-muted">结果:&nbsp;</span><strong class="text-danger">{{planResult}}￥</strong>
                </h5>
            </div>


        </div>
        <hr />
        <div class="panel panel-default">
            <div class="panel-heading">
                 <h5><a href="#" data-ng-init="summaryShow = false"  data-ng-click="summaryShow = !summaryShow">总结报告考核</a></h5>
            </div>
            <div class="panel-body">
                <div class="row" data-ng-show="summaryShow">
                    <div class="col-xs-12">
                        <form action="/" method="post">
                            <div class="form-group">
                                <label for="质量系数">质量系数</label>
                                <select class="form-control" required name="质量系数" data-ng-model="model_summary"
                                    data-ng-options="s for s in summaryRatio">
                                </select>
                            </div>
                        </form>
                    </div>

                </div>
                <button type="submit" class="btn btn-primary pull-right" data-ng-click="saveSummary()" data-ng-show="summaryShow">考核总结报告</button>
                <h5><span class="text-muted">额度:&nbsp;</span><strong>{{summaryTotal}}￥</strong>&nbsp;&nbsp;
                            <span class="text-muted">结果:&nbsp;</span><strong class="text-danger">{{summaryResult}}￥</strong>
                </h5>
            </div>
        </div>
        <hr />
        <div class="panel panel-default">
            <div class="panel-heading">
                <h5><a href="#" data-ng-init="qualityShow = false"  data-ng-click="qualityShow = !qualityShow">质量考核</a></h5>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-xs-12" data-ng-show="qualityShow">
                        <form action="/" method="post">
                            <div class="form-group">
                                <label for="质量系数">质量系数</label>
                                <select class="form-control" required name="质量系数" data-ng-model="model_quality"
                                    data-ng-options="s for s in qualityRatio">
                                </select>
                            </div>
                        </form>
                    </div>

                </div>
                <button data-ng-show="qualityShow" type="submit" class="btn btn-primary pull-right" data-ng-click="saveQuality()">考核工程质量</button>
                <h5><span class="text-muted">额度:&nbsp;</span><strong>{{qualityTotal}}￥</strong>&nbsp;&nbsp;
                            <span class="text-muted">结果:&nbsp;</span><strong class="text-danger">{{qualityResult}}￥</strong>
                </h5>
            </div>
        </div>
        <hr />
        <div class="panel panel-default">
            <div class="panel-heading">
                <h5><a href="#" data-ng-init="fileShow = false" data-ng-click="fileShow = !fileShow">资料归档考核</a></h5>
            </div>
            <div class="panel-body">
                <div class="row" data-ng-show="fileShow">
                    <div class="col-xs-12">
                        <form action="/" method="post">
                            <div class="form-group">
                                <label for="质量系数">质量系数</label>
                                <select class="form-control" required name="质量系数" data-ng-model="model_file"
                                    data-ng-options="s for s in fileRatio">
                                </select>
                            </div>
                        </form>
                    </div>

                </div>
                <button data-ng-show="fileShow"  type="submit" class="btn btn-primary pull-right" data-ng-click="saveFile()">考核资料归档</button>
                <h5><span class="text-muted">额度:&nbsp;</span><strong>{{fileTotal}}￥</strong>&nbsp;&nbsp;
                            <span class="text-muted">结果:&nbsp;</span><strong class="text-danger">{{fileResult}}￥</strong>
                </h5>
            </div>
        </div>

        <hr />
        <div class="panel panel-default">
            <div class="panel-heading">
                <h5><a href="#" data-ng-init="otherShow = false" data-ng-click="otherShow = !otherShow">其他考核</a></h5>
            </div>
            <div class="panel-body">
                <form data-ng-show="otherShow">
                    <div class="row">
                        <div class="col-xs-6">
                            <div class="form-group">
                                <label for="书面表扬次数">书面表扬次数</label>
                                <input class="form-control" type="number" min="0" max="100" step="1" name="书面表扬次数" data-ng-model="model_Praise" />
                            </div>
                            <div class="form-group">
                                <label for="项目内容">项目内容</label>
                                <select class="form-control" required name="项目内容" data-ng-model="model_ProjectContent"
                                    data-ng-options="s.value as s.label for s in ProjectContentItems">
                                </select>
                            </div>

                        </div>
                        <div class="col-xs-6">
                            <div class="form-group">
                                <label for="中间报告缺失">中间报告缺失</label>
                                <input class="form-control" type="number" min="0" max="100" step="1" required name="中间报告缺失"
                                    data-ng-model="model_Miss" />
                            </div>
                            <div class="form-group">
                                <label for="环境安全不达标">环境安全不达标</label>
                                <input class="form-control" type="number" min="0" max="100" step="1" required name="环境安全不达标"
                                    data-ng-model="model_Enviroment" />
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-6">
                            <div class="form-group">
                                <label for="所内检查">所内检查不合格次数</label>
                                <input class="form-control" type="number" min="0" max="100" step="1" name="所内检查" data-ng-model="model_PartmentReview" />
                            </div>
                            <div class="form-group">
                                <label for="外部检查">外部检查不合格次数</label>
                                <input class="form-control" type="number" min="0" max="100" step="1" required name="外部检查" data-ng-model="model_OuterReview" />
                            </div>
                        </div>
                        <div class="col-xs-6">
                            <div class="form-group">
                                <label for="内部检查">内部检查不合格次数</label>
                                <input class="form-control" type="number" min="0" required name="项目内容" data-ng-model="model_CorpReview" />
                            </div>
                        </div>
                    </div>
               
                </form>
              
                <button type="submit" class="btn btn-primary pull-right" data-ng-click="saveOthers()" data-ng-show="otherShow==true">考核其他</button>
                <h5>
                    <span class="text-muted">考核结果:&nbsp;</span><strong class="text-danger">{{otherResult}}￥</strong>
                </h5>
            </div>


        </div>
        <hr />

    </div>

</div>

<script type="text/javascript">
    var myapp = angular.module('myapp', []);
    myapp.controller('myCtrl', ['$scope', '$timeout', '$http', function ($scope, $timeout, $http)
    {
        
        $scope.Cost = '@ViewBag.Cost';//工作量考核费用
        var time = '2000-1-1';//默认时间,这里时间用不上,默认为2000
        var prjId = '@ViewBag.PrjId';//工程编号
        var title = '管理考核';//考核内容
        $scope.assessList = []; //所有初始数据
        
        $scope.collapse = function () {
            var panelShowArray = ['planShow', 'summaryShow', 'qualityShow', 'fileShow', 'otherShow'];
            var showState = $scope.planShow ? false : true;
            panelShowArray.forEach(function (itemStr) {
                $scope[itemStr] = showState;
            });
        };


        //Start 方案编写考核--------------
        (function()
        {
            $scope.QualityRatio = [1.2, 1.0, 0.6, 0];
            $scope.IsWritten = [{ label: "是", value: 1 }, { label: "否", value: 0.8 }];
            $scope.IsBid = [{ label: "是", value: 1 }, { label: "否", value: 0.5 }];
            $scope.IsAccompany = [{ label: "是", value: 0.3 }, { label: "否", value: 1 }];
            $scope.planTotal = (function ()
            {
                var max = $scope.Cost;
                if (max > 100000)
                {
                    max = 1000;
                }
                else if (max > 50000)
                {
                    max = 500;
                }
                else
                {
                    max = 200;
                }
                return max;
            })();
            $scope.savePlan = function ()
            {
                var namesArray = ['model_QualityRatio', 'model_IsBid', 'model_IsWritten', 'model_IsAccompany', 'planTotal', 'planResult'];

                try
                {
                    //先计算
                    $scope.planResult = 0;
                    var max = 0;
                    if ($scope.model_IsAccompany == 0.3)
                    {
                        $scope.model_IsBid = 0.5;
                        $scope.planResult = $scope.planTotal * $scope.model_QualityRatio * $scope.model_IsWritten * $scope.model_IsAccompany;
                    }
                    else
                    {
                        $scope.model_IsAccompany = 1;
                        $scope.planResult = $scope.planTotal * $scope.model_QualityRatio * $scope.model_IsWritten * $scope.model_IsBid;
                    }
                    $scope.planResult = $scope.planResult.toFixed(1);
                }
                catch (err)
                {
                    $scope.planResult = 0;
                }
                var insertArray = namesArray.map(function (item)
                {
                    return {
                        PrjId: prjId, Title: title, SubTitle: item, Time: time, Value: $scope[item] ? parseFloat($scope[item]) : 0
                    };
                });
                addItemsToDataBase(insertArray);

            };
        })();
        //end 方案编写考核--------------

        //start 总结报告
        (function()
        {
            $scope.summaryTotal = (function ()
            {
                var max = $scope.Cost;
                if (max > 100000)
                {
                    max = 2000;
                }
                else if (max > 50000)
                {
                    max = 800;
                }
                else
                {
                    max = 400;
                }
                return max;
            })();

            $scope.summaryRatio = [0.5, 0, -0.3, -1];

            $scope.saveSummary = function ()
            {
                try
                {

                    var value = $scope.model_summary * $scope.summaryTotal;
                    $scope.summaryResult = value.toFixed(1);
                    var namesArray = ['model_summary', 'summaryResult'];
                    var insertArray = namesArray.map(function (item)
                    {
                        return {
                            PrjId: prjId, Title: title, SubTitle: item, Time: time, Value: $scope[item] ? parseFloat($scope[item]) : 0
                        };
                    });
                    addItemsToDataBase(insertArray);
                }
                catch (err)
                {

                }
            };

        })();        
        //end 总结报告
        


        //start 工程质量
        (function ()
        {
            //quality
            $scope.qualityTotal = (function ()
            {
                var max = $scope.Cost;
                if (max > 100000)
                {
                    max = 3000;
                }
                else if (max > 50000)
                {
                    max = 2000;
                }
                else
                {
                    max = 1000;
                }
                return max;
            })();

            $scope.qualityRatio = [1.2, 1, 0.6, 0];

            $scope.saveQuality = function ()
            {
                try
                {

                    var value = ($scope.model_quality - 1) * $scope.qualityTotal;
                    $scope.qualityResult = value.toFixed(1);
                    var namesArray = ['model_quality', 'qualityResult'];
                    var insertArray = namesArray.map(function (item)
                    {
                        return {
                            PrjId: prjId, Title: title, SubTitle: item, Time: time, Value: $scope[item] ? parseFloat($scope[item]) : 0
                        };
                    });
                    addItemsToDataBase(insertArray);
                }
                catch (err)
                {

                }
            };

        })();
        //end 工程质量

        
        //start 归档
        (function ()
        {
            //file
            $scope.fileTotal = (function ()
            {
                var max = $scope.Cost;
                if (max > 100000)
                {
                    max = 500;
                }
                else if (max > 50000)
                {
                    max = 300;
                }
                else
                {
                    max = 200;
                }
                return max;
            })();

            $scope.fileRatio = [0, -0.5, -1];

            $scope.saveFile = function ()
            {
                try
                {

                    var value = $scope.model_file * $scope.fileTotal;
                    $scope.fileResult = value.toFixed(1);
                    var namesArray = ['model_file', 'fileResult'];
                    var insertArray = namesArray.map(function (item)
                    {
                        return {
                            PrjId: prjId, Title: title, SubTitle: item, Time: time, Value: $scope[item] ? parseFloat($scope[item]) : 0
                        };
                    });
                    addItemsToDataBase(insertArray);
                }
                catch (err)
                {

                }
            };

        })();
        //end 归档

        //start 其他考核
        (function () {
            $scope.ProjectContentItems = [{ label: "有", value: 0 }, { label: "无", value: -1 }];
            $scope.saveOthers = function () {
                try {
                    var array = ['model_Praise', 'model_ProjectContent', 'model_Miss', 'model_Enviroment', 'model_PartmentReview',
                                'model_OuterReview', 'model_CorpReview', 'otherResult'];
                    var max = $scope.model_Praise * 200 - $scope.model_Miss * 200 + $scope.model_ProjectContent * 200 -
                        $scope.model_Enviroment * 200 - $scope.model_PartmentReview * 100 - $scope.model_CorpReview * 300 -
                        $scope.model_OuterReview * 600;
                    $scope.otherResult = max;
                    var insertArray = array.map(function (item) {
                        return {
                            PrjId: prjId, Title: title, SubTitle: item, Time: time, Value: $scope[item] ? parseFloat($scope[item]) : 0
                        };
                    });
                    addItemsToDataBase(insertArray);
                } catch (err) {

                    $scope.otherResult = 0;
                }
            };

        })();
        //end   其他考核

      
        // ON Page Load
        (function () {
            $http({
                url: '@Url.Action("GetAssessItems","DoAssess")',
                method: 'get',
                params: { prjId: prjId, title: title }
            }).success(function (list)
            {
                $scope.assessList = list;
                //搜寻结果,所有的Scope变量命名将储存在Note属性里
                if (list.length === 0) return;
                for (var i = 0, max = list.length; i < max; i++)
                {
                    var item = list[i];
                    $scope[item.SubTitle] = item.Value;
                }
            });
        })();


        


      
        //帮助方法,存入数据库=_=,json 数组格
        function addItemsToDataBase(array)
        {
            $http({
                url: '@Url.Action("insertAssessItemArray","DoAssess")',
                method: 'post',
                data: {
                    jsonArray: JSON.stringify(array)
                }
            }).success(function (data)
            {
                //成功
                console.log("成功的插入json数组!!");
            });
        }
    }]);
</script>